package com.priserve.retirement.client.delegate;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.priserve.retirement.VO.ClientVo;
import com.priserve.retirement.client.exception.RetirementClientException;
import com.priserve.retirement.core.exception.RetirementCoreBusinessException;
import com.priserve.retirement.core.exception.RetirementCoreDataException;
import com.priserve.retirement.core.service.IAdvisorService;
import com.priserve.retirement.entities.Clientinformation;
import com.priserve.retirement.mapper.AdvisorMapper;

public class AdvisorDelegate {

	// updated by hemant
	
	@Autowired
	private IAdvisorService advisorService;


	
	public List<ClientVo> getClientInfoByAdvisor(final Long advisorId)
			throws RetirementClientException {

		List<ClientVo> clientsList=null;
		
		List<Clientinformation> clientInformationList;
		try {
			clientInformationList = advisorService.getClientInfoByAdvisor(advisorId);
		} catch (RetirementCoreBusinessException e) {
			
			e.printStackTrace();
			throw new RetirementClientException(e.getMessage());
		} catch (RetirementCoreDataException e) {
					e.printStackTrace();
			throw new RetirementClientException(e.getMessage());
		}
		
		if(clientInformationList!=null && !clientInformationList.isEmpty()){
		  clientsList=AdvisorMapper.mapClients(clientInformationList);
		}else{
			throw new RetirementClientException("No Clients are available for the selected Advisor...");
		}
		
		return clientsList;
 
				
		
	}
	
	
	
	
	
	
	
	
}
